// ============================================================================
//
// Copyright (C) 2006-2008 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.reports.editor.design.figures;

import org.dengues.reports.editor.design.layout.ReportColumnFillLayout;
import org.dengues.reports.editor.design.layout.ReportColumnToolbarLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-8-20 qiang.zhang $
 * 
 */
public class ReportTableColumnFigure extends RectangleFigure {

    private HeaderFigure name = new HeaderFigure();

    private ChildrenFigure childrenFigure = new ChildrenFigure();

    /**
     * Getter for childrenFigure.
     * 
     * @return the childrenFigure
     */
    public ChildrenFigure getChildrenFigure() {
        return this.childrenFigure;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com ReportTableColumnFigure constructor comment.
     */
    public ReportTableColumnFigure() {
        ToolbarLayout layout = new ReportColumnToolbarLayout();
        layout.setVertical(true);
        layout.setStretchMinorAxis(true);
        setLayoutManager(layout);
        setBorder(new LineBorder());
        setBackgroundColor(ColorConstants.white);
        setOpaque(false);
        name.setText("Header");
        add(name);
        add(childrenFigure);
        // setPreferredSize(100, -1);
    }

    class ChildrenFigure extends Figure {

        public ChildrenFigure() {
            ToolbarLayout layout = new ReportColumnFillLayout();
            layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
            layout.setStretchMinorAxis(true);
            layout.setVertical(true);
            layout.setSpacing(1);
            setLayoutManager(layout);
        }
    }

    class HeaderFigure extends Figure {

        private String text;

        private Label label;

        public HeaderFigure() {
            this.label = new Label();
            this.add(label);
            setOpaque(true);
        }

        public String getText() {
            return this.label.getText();
        }

        public Rectangle getTextBounds() {
            return this.label.getTextBounds();
        }

        public void setText(String text) {
            this.text = text;
            this.label.setText(text);
            this.repaint();
        }

        public void setBounds(Rectangle rect) {
            super.setBounds(rect);
            this.label.setBounds(rect);
        }
    }

}
